<template>
  <el-dialog
      :title="!dataForm.emrZyId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="病历节点编号" prop="emrJdId">
  <el-input v-model="dataForm.emrJdId" placeholder="病历节点编号"></el-input>

</el-form-item>
<el-form-item label="就诊时间" prop="emrZyDate">
  <el-input v-model="dataForm.emrZyDate" placeholder="就诊时间"></el-input>

</el-form-item>
<el-form-item label="就诊科室" prop="emrZyKs">
  <el-input v-model="dataForm.emrZyKs" placeholder="就诊科室"></el-input>

</el-form-item>
<el-form-item label="过敏信息" prop="emrZyGm">
  <el-input v-model="dataForm.emrZyGm" placeholder="过敏信息"></el-input>

</el-form-item>
<el-form-item label="主诉" prop="emrZyMain">
  <el-input v-model="dataForm.emrZyMain" placeholder="主诉"></el-input>

</el-form-item>
<el-form-item label="现病史" prop="emrZyNow">
  <el-input v-model="dataForm.emrZyNow" placeholder="现病史"></el-input>

</el-form-item>
<el-form-item label="既往史" prop="emrZyBefore">
  <el-input v-model="dataForm.emrZyBefore" placeholder="既往史"></el-input>

</el-form-item>
<el-form-item label="个人史" prop="emrZyPerson">
  <el-input v-model="dataForm.emrZyPerson" placeholder="个人史"></el-input>

</el-form-item>
<el-form-item label="婚育史" prop="emrZyMarry">
  <el-input v-model="dataForm.emrZyMarry" placeholder="婚育史"></el-input>

</el-form-item>
<el-form-item label="家族史" prop="emrZyFamily">
  <el-input v-model="dataForm.emrZyFamily" placeholder="家族史"></el-input>

</el-form-item>
<el-form-item label="望诊" prop="emrZyLook">
  <el-input v-model="dataForm.emrZyLook" placeholder="望诊"></el-input>

</el-form-item>
<el-form-item label="闻诊" prop="emrZySmell">
  <el-input v-model="dataForm.emrZySmell" placeholder="闻诊"></el-input>

</el-form-item>
<el-form-item label="切诊" prop="emrZyPluse">
  <el-input v-model="dataForm.emrZyPluse" placeholder="切诊"></el-input>

</el-form-item>
<el-form-item label="查体" prop="emrZyBody">
  <el-input v-model="dataForm.emrZyBody" placeholder="查体"></el-input>

</el-form-item>
<el-form-item label="辅助检查" prop="emrZyCheck">
  <el-input v-model="dataForm.emrZyCheck" placeholder="辅助检查"></el-input>

</el-form-item>
<el-form-item label="中医诊断" prop="emrZyDeal">
  <el-input v-model="dataForm.emrZyDeal" placeholder="中医诊断"></el-input>

</el-form-item>
<el-form-item label="西医诊断" prop="emrXyDeal">
  <el-input v-model="dataForm.emrXyDeal" placeholder="西医诊断"></el-input>

</el-form-item>
<el-form-item label="药物治疗" prop="emrZyDrugs">
  <el-input v-model="dataForm.emrZyDrugs" placeholder="药物治疗"></el-input>

</el-form-item>
<el-form-item label="处方" prop="emrZyResult">
  <el-input v-model="dataForm.emrZyResult" placeholder="处方"></el-input>

</el-form-item>
<el-form-item label="处理人姓名" prop="emrYsName">
  <el-input v-model="dataForm.emrYsName" placeholder="处理人姓名"></el-input>

</el-form-item>
<el-form-item label="处理人编号" prop="emrYsId">
  <el-input v-model="dataForm.emrYsId" placeholder="处理人编号"></el-input>

</el-form-item>
<el-form-item label="病历图片原件" prop="emrZyImg">
  <el-input v-model="dataForm.emrZyImg" placeholder="病历图片原件"></el-input>

</el-form-item>
<el-form-item label="面诊照片" prop="emrZyFaceImgs">
  <el-input v-model="dataForm.emrZyFaceImgs" placeholder="面诊照片"></el-input>

</el-form-item>
<el-form-item label="舌诊照片" prop="emrZyTongueImgs">
  <el-input v-model="dataForm.emrZyTongueImgs" placeholder="舌诊照片"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          emrZyId: 0,
          emrJdId: '',
          emrZyDate: '',
          emrZyKs: '',
          emrZyGm: '',
          emrZyMain: '',
          emrZyNow: '',
          emrZyBefore: '',
          emrZyPerson: '',
          emrZyMarry: '',
          emrZyFamily: '',
          emrZyLook: '',
          emrZySmell: '',
          emrZyPluse: '',
          emrZyBody: '',
          emrZyCheck: '',
          emrZyDeal: '',
          emrXyDeal: '',
          emrZyDrugs: '',
          emrZyResult: '',
          emrYsName: '',
          emrYsId: '',
          emrZyImg: '',
          emrZyFaceImgs: '',
          emrZyTongueImgs: ''
        },
        dataRule: {
          emrJdId: [
            { required: true, message: '病历节点编号不能为空', trigger: 'blur' }
          ],
          emrZyDate: [
            { required: true, message: '就诊时间不能为空', trigger: 'blur' }
          ],
          emrZyKs: [
            { required: true, message: '就诊科室不能为空', trigger: 'blur' }
          ],
          emrZyGm: [
            { required: true, message: '过敏信息不能为空', trigger: 'blur' }
          ],
          emrZyMain: [
            { required: true, message: '主诉不能为空', trigger: 'blur' }
          ],
          emrZyNow: [
            { required: true, message: '现病史不能为空', trigger: 'blur' }
          ],
          emrZyBefore: [
            { required: true, message: '既往史不能为空', trigger: 'blur' }
          ],
          emrZyPerson: [
            { required: true, message: '个人史不能为空', trigger: 'blur' }
          ],
          emrZyMarry: [
            { required: true, message: '婚育史不能为空', trigger: 'blur' }
          ],
          emrZyFamily: [
            { required: true, message: '家族史不能为空', trigger: 'blur' }
          ],
          emrZyLook: [
            { required: true, message: '望诊不能为空', trigger: 'blur' }
          ],
          emrZySmell: [
            { required: true, message: '闻诊不能为空', trigger: 'blur' }
          ],
          emrZyPluse: [
            { required: true, message: '切诊不能为空', trigger: 'blur' }
          ],
          emrZyBody: [
            { required: true, message: '查体不能为空', trigger: 'blur' }
          ],
          emrZyCheck: [
            { required: true, message: '辅助检查不能为空', trigger: 'blur' }
          ],
          emrZyDeal: [
            { required: true, message: '中医诊断不能为空', trigger: 'blur' }
          ],
          emrXyDeal: [
            { required: true, message: '西医诊断不能为空', trigger: 'blur' }
          ],
          emrZyDrugs: [
            { required: true, message: '药物治疗不能为空', trigger: 'blur' }
          ],
          emrZyResult: [
            { required: true, message: '处方不能为空', trigger: 'blur' }
          ],
          emrYsName: [
            { required: true, message: '处理人姓名不能为空', trigger: 'blur' }
          ],
          emrYsId: [
            { required: true, message: '处理人编号不能为空', trigger: 'blur' }
          ],
          emrZyImg: [
            { required: true, message: '病历图片原件不能为空', trigger: 'blur' }
          ],
          emrZyFaceImgs: [
            { required: true, message: '面诊照片不能为空', trigger: 'blur' }
          ],
          emrZyTongueImgs: [
            { required: true, message: '舌诊照片不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.emrZyId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.emrZyId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrzymodel/info/${this.dataForm.emrZyId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.emrJdId = data.emrZyModel.emrJdId
                this.dataForm.emrZyDate = data.emrZyModel.emrZyDate
                this.dataForm.emrZyKs = data.emrZyModel.emrZyKs
                this.dataForm.emrZyGm = data.emrZyModel.emrZyGm
                this.dataForm.emrZyMain = data.emrZyModel.emrZyMain
                this.dataForm.emrZyNow = data.emrZyModel.emrZyNow
                this.dataForm.emrZyBefore = data.emrZyModel.emrZyBefore
                this.dataForm.emrZyPerson = data.emrZyModel.emrZyPerson
                this.dataForm.emrZyMarry = data.emrZyModel.emrZyMarry
                this.dataForm.emrZyFamily = data.emrZyModel.emrZyFamily
                this.dataForm.emrZyLook = data.emrZyModel.emrZyLook
                this.dataForm.emrZySmell = data.emrZyModel.emrZySmell
                this.dataForm.emrZyPluse = data.emrZyModel.emrZyPluse
                this.dataForm.emrZyBody = data.emrZyModel.emrZyBody
                this.dataForm.emrZyCheck = data.emrZyModel.emrZyCheck
                this.dataForm.emrZyDeal = data.emrZyModel.emrZyDeal
                this.dataForm.emrXyDeal = data.emrZyModel.emrXyDeal
                this.dataForm.emrZyDrugs = data.emrZyModel.emrZyDrugs
                this.dataForm.emrZyResult = data.emrZyModel.emrZyResult
                this.dataForm.emrYsName = data.emrZyModel.emrYsName
                this.dataForm.emrYsId = data.emrZyModel.emrYsId
                this.dataForm.emrZyImg = data.emrZyModel.emrZyImg
                this.dataForm.emrZyFaceImgs = data.emrZyModel.emrZyFaceImgs
                this.dataForm.emrZyTongueImgs = data.emrZyModel.emrZyTongueImgs
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrzymodel/${!this.dataForm.emrZyId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'emrZyId': this.dataForm.emrZyId || undefined,
                'emrJdId': this.dataForm.emrJdId,
                'emrZyDate': this.dataForm.emrZyDate,
                'emrZyKs': this.dataForm.emrZyKs,
                'emrZyGm': this.dataForm.emrZyGm,
                'emrZyMain': this.dataForm.emrZyMain,
                'emrZyNow': this.dataForm.emrZyNow,
                'emrZyBefore': this.dataForm.emrZyBefore,
                'emrZyPerson': this.dataForm.emrZyPerson,
                'emrZyMarry': this.dataForm.emrZyMarry,
                'emrZyFamily': this.dataForm.emrZyFamily,
                'emrZyLook': this.dataForm.emrZyLook,
                'emrZySmell': this.dataForm.emrZySmell,
                'emrZyPluse': this.dataForm.emrZyPluse,
                'emrZyBody': this.dataForm.emrZyBody,
                'emrZyCheck': this.dataForm.emrZyCheck,
                'emrZyDeal': this.dataForm.emrZyDeal,
                'emrXyDeal': this.dataForm.emrXyDeal,
                'emrZyDrugs': this.dataForm.emrZyDrugs,
                'emrZyResult': this.dataForm.emrZyResult,
                'emrYsName': this.dataForm.emrYsName,
                'emrYsId': this.dataForm.emrYsId,
                'emrZyImg': this.dataForm.emrZyImg,
                'emrZyFaceImgs': this.dataForm.emrZyFaceImgs,
                'emrZyTongueImgs': this.dataForm.emrZyTongueImgs
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
